package cn.cxyxj.study06.model;

import cn.cxyxj.study06.entity.SysUser;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

@Data
public class SysUserDetails implements UserDetails {

    private SysUser sysUser;

    private Collection<? extends GrantedAuthority> authorities;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return sysUser.getPassword();
    }

    @Override
    public String getUsername() {
        return sysUser.getAccount();
    }

    /**
     * 账户是否未过期
     */

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }


    /**
     * 账户是否未锁定
     */

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }


    /**
     * 凭证是否未过期
     */

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }


    /**
     * 账户是否启用
     *
     * @return
     */

    @Override
    public boolean isEnabled() {
        return true;
    }

    public SysUser getSysUser() {
        return sysUser;
    }

    public void setSysUser(SysUser sysUser) {
        this.sysUser = sysUser;
    }

    public SysUserDetails(SysUser sysUser, Collection<? extends GrantedAuthority> authorities) {
        this.sysUser = sysUser;
        this.authorities = authorities;
    }
}